package com.example.myzhujielearing;

import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.bottonknife.ButtonKnife;
import com.example.compiler.BindView;
import com.example.compiler.MyAnnotion;
import com.example.compiler.ViewBind;

import java.lang.reflect.Method;

/**
 * gradel 5.1之上 看compiler中的gradle 中的implementation与annotationProcessor都要
 * implementation 'com.google.auto.service:auto-service:1.0-rc2'
 * annotationProcessor  'com.google.auto.service:auto-service:1.0-rc2'
 */
public class SecondActivity extends AppCompatActivity {

    @ViewBind(R.id.tv_1)
    public TextView textView;

    @ViewBind(R.id.tv_2)
    public TextView textView2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second_main);
        reflectNewInstance();

        ButtonKnife.bind(this);
        textView.setText("SecondActivity绑定的注解");
        textView2.setText("绑定的注解textView2");
    }

    // 创建对象
    public static void reflectNewInstance() {
        try {
            Class<?> classBook = Class.forName("com.example.demoprocessor.auto.Tgwlieming$$ZYAO");

            Method methodBook = classBook.getDeclaredMethod("getMessage");
            methodBook.setAccessible(true);
            Object objectBook = classBook.newInstance();
            String string = (String) methodBook.invoke(objectBook);
            Log.d("tgw注解", "reflectNewInstance book = " + string);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}
